export const  getopts = (args, opts)=> {
  var result = opts.default || {}
  args.replace(new RegExp('([^?=&]+)(=([^&]*))?', 'g'), function(
    $0,
    $1,
    $2,
    $3
  ) {
    result[$1] = $3
  })

  return result
}

export const setIceCandidateCallbacks=(webRtcEndpoint, webRtcPeer, onError)=> {
  webRtcPeer.on('icecandidate', function(candidate) {
    console.log('Local icecandidate ' + JSON.stringify(candidate))

    candidate = kurentoClient.register.complexTypes.IceCandidate(candidate)

    webRtcEndpoint.addIceCandidate(candidate, onError)
  })
  webRtcEndpoint.on('OnIceCandidate', function(event) {
    var candidate = event.candidate

    console.log('Remote icecandidate ' + JSON.stringify(candidate))

    webRtcPeer.addIceCandidate(candidate, onError)
  })
}

export const onError=(error)=> {
  if (error) {
    console.error(error)
    stop()
  }
}

export const showSpinner=()=> {
  for (var i = 0; i < arguments.length; i++) {
    // arguments[i].poster = 'img/transparent-1px.png'
    // arguments[i].style.background =
    //   "center transparent url('img/spinner.gif') no-repeat"
  }
}

export const hideSpinner=()=> {
  // for (var i = 0; i < arguments.length; i++) {
  //   arguments[i].src = ''
  //   arguments[i].poster = 'img/webrtc.png'
  //   arguments[i].style.background = ''
  // }
}


